<?
	$title="Add User Role";
	$mid=5;
	require("required/dbconnect.php");
	require_once("required/function.php");
	//checkAccess();
	
	if(isset($_POST['btnsubmit']))
	{
		$role_name=mysql_escape_string($_POST['role_name']);
		
		$query_field="insert into os_user_role(role_name,";
		$query_values=")values('$role_name',";
		
		if(!empty($_POST['accessright']))
		{
			$accessright=$_POST['accessright'];
			
			for($i=0;$i<count($accessright);$i++)
			{
				$query_field.=$accessright[$i].",";
				$query_values.="1,";			
			}
			
			
		}
		
		$query_field=rtrim($query_field,",");
		$query_values=rtrim($query_values,",");
		
		$query_full=$query_field.$query_values.")";
		
		
		mysql_query($query_full)or die(mysql_error());
		header("Location:user_role_view_all.php?action=1");
	}
	
	
	require("required/header.php");


?>
<script src="required/js/jquery-1.4.2.js"></script>
<script src="required/js/common_javascript.js"></script>
<?	
		
	if(!empty($_GET['action']))
	{
		
		switch($_GET['action'])
		{
			case 1:
				$msg="<div class='dw_success'>Data inserted</div>";
				break;
			case 2:
				$msg="<div class='dw_success'>Data Deleted</div>";
				break;
			case 3:
				$msg="<div class='dw_success'>Data Updated</div>";
				break;	
			default:
				$msg="";
				break;
		}
		echo "<script>displayMsg('divMsg')</script>";	
	}else{
		$msg="";
	}
	
	
	
?>
<script>
	function frmvalidate(addfrm)
	{
		if(document.addfrm.role_name.value=="")
		{
			alert("Please insert role name");
			document.addfrm.role_name.focus();
			return false;
		}
		return true;
	}
	
	
	
</script>
<table width="100%">
 
<td valign="top" align="left">
       <table width="95%" align="center">
       		<tr>
            	<td class="title"><?= $title ?></td>
            </tr>
            <tr>
            	<td><div id="divMsg"><?= $msg ?></div></td>
            </tr>
            <tr>
            	<td>
                  <br>
                    
                 
                  <form action="<?= $_SERVER['PHP_SELF'] ?>" method="post" name="addfrm" onSubmit="return frmvalidate(this)">
                    	Role Name : <input type="text" name="role_name" size="30" maxlength="100">
                        <br />
                         <br />
                        <table>
                         
                          <Tr>
                          	<Td colspan="3"><strong>Home</strong></Td>
                          </Tr>
                          <tr valign="middle">
                         	 <td><input type="checkbox" name="accessright[]" value="allow_statistic_view" align="absmiddle" /> Allow View Site Statistic</td><td></td> 
                          </tr>
                           
                           <tr>
                          	<Td><br /></Td>
                          </tr>	
                          <Tr>
                          	<Td colspan="3"><strong>Product Management</strong></Td>
                          </Tr>
                          <tr valign="middle">
                         	 <td><input type="checkbox" name="accessright[]" value="allow_product_management" align="absmiddle" /> Allow Product Management</td><td></td> 
                          </tr>
                           <tr valign="middle">
                           
                            <td><input type="checkbox" name="accessright[]" value="allow_product_add" /> Allow Add Product</td><td></td> 
                            <td><input type="checkbox" name="accessright[]" value="allow_product_edit" /> Allow Edit Product</td><td></td> 
                            <td><input type="checkbox" name="accessright[]" value="allow_product_delete" /> Allow Delete Product</td><td></td>
                           
                          </tr>
                          
                           <tr>
                          	<Td><br /></Td>
                          </tr>
                           <Tr>
                          	<Td colspan="3"><strong>Gift / Coupons</strong></Td>
                          </Tr>		
                          <tr>
                            <td><input type="checkbox" name="accessright[]" value="allow_gift_management" /> Allow Gift/Coupon Management</td><td></td>
                          </tr>
                          <tr>
                          	<Td><br /></Td>
                          </tr>
                          <Tr>
                          	<Td colspan="3"><strong>Branch Purchase Management</strong></Td>
                          </Tr>
                          <tr valign="middle">
                         	 <td><input type="checkbox" name="accessright[]" value="allow_branch_management" align="absmiddle" /> Allow Branch Purchase Management</td><td></td> 
                          </tr>		
                          <tr>
                          	<td><input type="checkbox" name="accessright[]" value="allow_branch_member_view" /> Allow View Branch Member</td><td></td> 
                            <td><input type="checkbox" name="accessright[]" value="allow_branch_member_add" /> Allow Add Branch Member</td><td></td> 
                            <td><input type="checkbox" name="accessright[]" value="allow_branch_member_edit" /> Allow Edit Branch Member</td><td></td> 
                            <td><input type="checkbox" name="accessright[]" value="allow_branch_member_delete" /> Allow Delete Branch Member</td><td></td>
                          </tr>
                          <tr>
                            <td><input type="checkbox" name="accessright[]" value="allow_branch_sales_view" /> Allow View Branch Sales</td><td></td> 
                            <td><input type="checkbox" name="accessright[]" value="allow_branch_sales_add" /> Allow Add Branch Sales</td><td></td> 
                            <td><input type="checkbox" name="accessright[]" value="allow_branch_sales_edit" /> Allow Edit Branch Sales</td><td></td> 
                            <td><input type="checkbox" name="accessright[]" value="allow_branch_sales_delete" /> Allow Delete Branch Sales</td><td></td> 
                          </tr>
                            <tr>
                          	<Td><br /></Td>
                          </tr>
                          <Tr>
                          	<Td colspan="3"><strong>E-Shopping Management</strong></Td>
                          </Tr>
                           <tr valign="middle">
                         	 <td><input type="checkbox" name="accessright[]" value="allow_shopping_management" align="absmiddle" /> Allow E-Shopping Management</td><td></td> 
                          </tr>		
                          
                          <tr>
   							<td><input type="checkbox" name="accessright[]" value="allow_online_member_view" /> Allow View Online Member</td><td></td> 
                            <td><input type="checkbox" name="accessright[]" value="allow_online_member_edit" /> Allow Edit Online Member</td><td></td> 
                            <td><input type="checkbox" name="accessright[]" value="allow_online_member_delete" /> Allow Delete Online Member</td><td></td>
                          </tr>
                           
                           <tr>
                            <td><input type="checkbox" name="accessright[]" value="allow_online_sales_view" /> Allow View Online Sales</td><td></td> 
                          
                            <td><input type="checkbox" name="accessright[]" value="allow_online_sales_edit" /> Allow Edit Online Sales</td><td></td> 
                            <td><input type="checkbox" name="accessright[]" value="allow_online_sales_delete" /> Allow Delete Online Sales</td><td></td> 
                
                          </tr>
                           <tr>
                          	<Td><br /></Td>
                          </tr>
                         <Tr>
                          	<Td colspan="3"><strong>Shipping</strong></Td>
                          </Tr>		
                          <tr>
                            <td><input type="checkbox" name="accessright[]" value="allow_shipping_management" /> Allow Shipping Management</td><td></td>
                          </tr>
                          <tr>
                          	<Td><br /></Td>
                          </tr>
                         
                         
                           <Tr>
                          	<Td colspan="3"><strong>Content</strong></Td>
                          </Tr>		
                          <tr>
                            <td><input type="checkbox" name="accessright[]" value="allow_content_management" /> Allow Content Management</td><td></td>
                          </tr>
                          <tr>
                          	<Td><br /></Td>
                          </tr>
                          <Tr>
                          	<Td colspan="3"><strong>User</strong></Td>
                          </Tr>		
                          <tr>
                            <td><input type="checkbox" name="accessright[]" value="allow_user_management" /> Allow User Management</td><td></td> 
                            
                          </tr>
                           <tr>
                          	<Td><br /></Td>
                          </tr>
                          <Tr>
                          	<Td colspan="3"><strong>System Management</strong></Td>
                          </Tr>		
                          <tr>
                            <td><input type="checkbox" name="accessright[]" value="allow_system_management" /> Allow System Management</td><td></td>  
                          </tr>
                    	</table>
                        <br /><br />
                        <input type="submit" value="Add" name="btnsubmit">
                        
                        <input type="button" value="Back" onclick="history.go(-1)">
                  </form>
              </td>
            </tr>
       </table>
       
    </td>
</table>					
<?
	require("required/footer.php");
?>               
        